package com.lsa.skienna.challenge.chap1;

import java.io.BufferedInputStream;
import java.io.FileInputStream;

import junit.framework.TestCase;

import com.lsa.helpers.Utils;
import com.lsa.skienna.challenge.chap1.Mines.MineSweeper;
import com.lsa.skienna.challenge.chap1.Mines.TaskReader;

public class TestMines extends TestCase {
	public void testReader() throws Throwable{
		TaskReader reader = new TaskReader(new FileInputStream("data/pc1/mines/fields.txt"));
		int[][] task = reader.readNextTask();
		assertTrue(Utils.compareArrays(task, 
				new int[][]{
					{-1,0,0,0},
					{0,0,0,0},
					{0,-1,0,0},
					{0,0,0,0}
				}));
		task = reader.readNextTask();
		assertTrue(Utils.compareArrays(task, 
				new int[][]{
					{-1,-1,0,0,0},
					{0,0,0,0,0},
					{0,-1,0,0,0}
				}));
	}
	
	public void testMineSweeper() throws Throwable{
		TaskReader reader = new TaskReader(new FileInputStream("data/pc1/mines/fields.txt"));
		int[][] task = reader.readNextTask();
		MineSweeper sweeper = new MineSweeper();
		int[][] result = sweeper.processTask(task);
		assertTrue(Utils.compareArrays(result, 
				new int[][]{
					{-1, 1, 0, 0},
					{ 2, 2, 1, 0},
					{ 1,-1, 1, 0},
					{ 1, 1, 1, 0}
				}));
		task = reader.readNextTask();
		result = sweeper.processTask(task);
		assertTrue(Utils.compareArrays(result, 
				new int[][]{
					{-1, -1, 1, 0, 0},
					{ 3, 3, 2, 0, 0},
					{ 1,-1, 1, 0, 0},
				}));
	}
	
	public void testAll() throws Throwable{
		System.setIn(new BufferedInputStream(new FileInputStream("data/pc1/mines/fields.txt")));
		new Mines().run();
	}
}
